package com.zmj.sy.mom.srv.aps.service.scheduler.extractor;

import com.zmj.sy.mom.srv.aps.bean.entity.resource.*;
import com.zmj.sy.mom.srv.aps.mapper.*;
import com.zmj.sy.mom.srv.aps.service.scheduler.inverted.InvertedScheduleContext;
import com.zmj.sy.mom.srv.aps.service.scheduler.inverted.InvertedScheduleOrder;
import com.zmj.sy.mom.srv.aps.service.scheduler.resource.DefaultCalendar;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor
public class CalendarExtractor {

    private final ShiftTypeMapper shiftTypeMapper;

    private final ShiftMapper shiftMapper;

    private final BreakPeriodMapper breakPeriodMapper;

    private final WeekdayRuleMapper weekdayRuleMapper;

    public DefaultCalendar load(InvertedScheduleContext context, InvertedScheduleOrder order) {
        DefaultCalendar calendar = new DefaultCalendar();

        List<ShiftType> shiftTypes = shiftTypeMapper.lambdaQuery()
                .list();
        calendar.setShiftTypes(shiftTypes);

        List<Shift> shifts = shiftMapper.lambdaQuery()
                .in(Shift::getShiftTypeId, calendar.shiftTypeIds())
                .list();
        calendar.setShifts(shifts);

        List<WeekdayRule> weekdayRules = weekdayRuleMapper.lambdaQuery()
                .in(WeekdayRule::getShiftTypeId, calendar.shiftTypeIds())
                .list();
        calendar.setShiftRules(weekdayRules);

        List<BreakPeriod> breakPeriods = breakPeriodMapper.lambdaQuery()
                .list();
        calendar.setBreakPeriods(breakPeriods);

        return calendar;
    }

}
